// 兼容
import 'core-js/stable';
import 'regenerator-runtime/runtime';

import Vue from 'vue';

import Cookies from 'js-cookie';

import 'normalize.css/normalize.css'; // a modern alternative to CSS resets

import Element from 'element-ui';
import './styles/element-variables.scss';

import '@/styles/index.scss'; // global css

import App from './App';
import store from './store';
import router from './router';
import permission from './directive/permission';

import './icons'; // icon
import './permission'; // permission control
import './utils/error-log'; // error log

// 弹窗放大缩小
import elDragDialog from './directive/el-drag-dialog';
Vue.directive('elDragDialog', elDragDialog);

// 通用方法挂载
import { getDicts } from '@/api/basicdata/basictype';
import {parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree} from '@/utils/boostor';
Vue.prototype.getDicts = getDicts;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;

// 分页组件+工具栏组件
import Pagination from '@/components/Pagination';
import RightToolbar from '@/components/RightToolbar';

// 全局过滤器
import * as filters from './filters';

// 消息提示
Vue.prototype.msgSuccess = function (msg) {
  this.$message({ showClose: true, message: msg, type: 'success' });
};
Vue.prototype.msgError = function (msg) {
  this.$message({ showClose: true, message: msg, type: 'error' });
};
Vue.prototype.msgWarning = function (msg) {
  this.$message({ showClose: true, message: msg, type: 'warn' });
};
Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
};

Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;

// 修改 el-dialog 默认点击遮照为不关闭
Element.Dialog.props.closeOnClickModal.default = false;

// 全局组件挂载
Vue.component('Pagination', Pagination);
Vue.component('RightToolbar', RightToolbar);

Vue.use(permission);

Vue.use(Element, {
  size: Cookies.get('size') || 'medium',
});

Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});

Vue.config.productionTip = false;

new Vue({
  el: '#app',
  router,
  store,
  render: (h) => h(App),
});
